package com.mf.springcloud.controller;

import com.mf.springcloud.entity.Article;
import com.mf.springcloud.service.ArticleClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ArticleController {

    private static  final  String REST_URL_PREFIX="http://microservicecloud-provider";

    @Autowired
    private RestTemplate restTemplate;


    @RequestMapping(value="/consumer/article/add",method = RequestMethod.GET)
    public boolean add(Article article){
        return restTemplate.postForObject(REST_URL_PREFIX+"/article/add",article,Boolean.class);
    }

    @RequestMapping(value="/consumer/article/get/{id}",method = RequestMethod.GET)
    public Article get(@PathVariable("id") Integer id){
        return restTemplate.getForObject(REST_URL_PREFIX+"/article/get/"+id,Article.class);
    }
    @RequestMapping(value="/consumer/article/discovery")
    public Object discovery(){
        return  restTemplate.getForObject(REST_URL_PREFIX+"/article/discovery",Object.class);
    }




}
